<?php
	include('sys.fun.php');
	//第一步，接收前面表单中的值
	//userid 和  password
	//接收$_POST['userid']   $_POST['password']
	//判断变量是否由表单创建
	if(isset($_POST['userid']))
	{
		 $name = $_POST['userid'];
		 $name = trim($name);//去掉空格
		 $name = htmlspecialchars($name);//不翻译html
		 $password = $_POST['password'];
		 $password = trim($password);//去掉空格
		 $password = htmlspecialchars($password);//不翻译html
		 //获取数据库信息
		 $servername = "localhost";
		 $MYSQL_username = "root";
		 $MYSQL_password = "";
		 $dbname = "myd";
		 
		 //创建连接
		 $conn = new mysqli($servername, $MYSQL_username, $MYSQL_password,$dbname);
		 
		 // 检测连接
		 if ($conn->connect_error)
		 {
		     die("连接失败: " . $conn->connect_error);
		 }
		 $sql = "select u_name,u_password from m_userpassword";
	 	 $result = $conn->query($sql);
	 	 
	 	 //比对数据
	 	 if($result->num_rows > 0)
	 	 {
	 	 	$u_exit = 0;//判断用户是否存在
	 	 	while($row = $result->fetch_assoc())
	 	 	{
	 	 		if($row['u_name'] == $name)
	 	 		{
	 	 			$u_exit = 1;		
	 	 			if($row['u_password'] == $password)
	 	 			{
	 	 				echo '<h1>将在不久后跳转</h1>';
	 	 				setcookie('name','DYW');
	 	 				header("Refresh:0;index.php");
	 	 				exit;
	 	 			}else
	 	 			{
	 	 				echo "<script>alert('密码错误！');</script>";
	 	 				header("Refresh:0;login.html");
	 	 				exit;
	 	 			}
	 	 		}
	 	 	}
	 	 	if($u_exit == 0)
	 	 	{
	 	 		echo "<script>alert('用户不存在！');</script>";
	 	 		header("Refresh:0;login.html");
	 	 		exit;
	 	 	}else
	 	 	{
	 	 		//用户存在
	 	 	}
	 	 }
	}else
	{
		echo "<script>alert('用户名为空！');</script>";
		header("Refresh:0;login.html");
		exit;
	}
	
?>